/* 对象本质都是Object, 花括号是其简写 */

/* 1.标准的对象 */
function es5Obj() {
    let name = "xiaoming";
    let age = 12;
    let student = {
        name: name,
        age: age
    }
    name = 18;
    console.log(student);   // { name: 'xiaoming', age: 12 }
}

/* 2.这里传的是值而不是引用 */
function es6Obj() {
    let name = "xiaoming";
    let age = 12;
    let student = {
        name,
        age
    }
    name = 18;
    console.log(student);  // { name: 'xiaoming', age: 12 }
}

/* 3.属性表达式 */
function es6ObjRef() {
    let key = "name";
    let myName = "xiaoming";
    let student = {
        [key]: myName
    }
    key = "name1";
    console.log(student);  // { name: 'xiaoming' }    
}

/* 4.新的Api: is assign */
function newObjApi() {
    console.log('字符串', Object.is('abc', 'abc'), 'abc' === 'abc');   // 字符串 true true
    console.log('数组', Object.is([], []), [] === []);                 // 数组 false false
    console.log('拷贝', Object.assign({ a: 'a' }, { b: 'b' }));        // 拷贝 { a: 'a', b: 'b' }
}

/* 5.获得所有对象属性的名字和值 */
function getAllField1() {
    let student = {
        name: "xiaoming",
        age: 12
    }
    let keyList = Reflect.ownKeys(student);
    console.log(keyList);   // [ 'name', 'age' ]
    /* 遍历所有的值 */
    keyList.forEach(item => console.log(student[item]));
}

/* 6.获得所有对象属性的名字和值 */
function getAllField2() {
    let student = {
        name: "xiaoming",
        age: 12
    }
    let keyList = Object.getOwnPropertyNames(student);
    console.log(keyList);   // [ 'name', 'age' ]
    /* 遍历所有的值 */
    keyList.forEach(item => console.log(student[item])); 
}